<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>商品评价页面</title>
<link rel="stylesheet"
	href="/wk1un2_electricity_digital/Backstage/layui/css/layui.css" />
</head>

<body>

	<div class="layui-form" style="margin-top: 20px;" onsubmit="false">
		<div class="layui-form-item">
			<label class="layui-form-label">评价内容</label>
			<div class="layui-input-inline">
				<input type="text" name="e_contents" id="e_contents" placeholder="请输入评价信息"
					class="layui-input">
			</div>
			
			<button class="layui-btn" id="search" data-type="reload">查询</button>
		</div>
	</div>
	<table class="layui-hide" id="test" lay-filter="test"></table>
	<script type="text/html" id="barDemo">
			<!--在表格的行内加的工具-->
			<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
		</script>
		 <script type="text/html" id="userTpl">
      {{#  if(d.u_id == 1){ }}
          <span style="color: #F581B1;">李四</span>
      {{#  } else if(d.u_id == 2){ }}
          <span style="color: #1e9fff;">王五</span>
      {{#  } else if(d.u_id == 3){ }}
          <span style="color: #08f55f;">小明</span>
      {{#  } else if(d.u_id == 4){ }}
          <span style="color: #08f55f;">张三</span>
      {{#  }else if(d.u_id == 5){ }}
          <span style="color: #08f55f;">赵六</span>
      {{#  }else if(d.u_id == 6){ }}
          <span style="color: #08f55f;">张三</span>
      {{#  } }}
         </script>
          <script type="text/html" id="proTpl">
      {{#  if(d.p_id == 1){ }}
          <span style="color: #F581B1;">HUAWEI Mate 40 Pro 5G 全网通</span>
      {{#  } else if(d.p_id == 2){ }}
          <span style="color: #1e9fff;">荣耀Play4</span>
      {{#  } else if(d.p_id == 3){ }}
          <span style="color: #08f55f;">HUAWEI MateBook X</span>
      {{#  }else if(d.p_id == 4){ }}
          <span style="color: #08f55f;">荣耀MagicBook Pro</span>
      {{#  }else if(d.p_id == 5){ }}
          <span style="color: #08f55f;">华为MatePad Pro</span>
      {{#  }else if(d.p_id == 6){ }}
          <span style="color: #08f55f;">荣耀平板V6</span>
      {{#  }else if(d.p_id == 7){ }}
          <span style="color: #08f55f;">华为FreeBuds 3</span>
      {{#  } }}
         </script>
	<!--检查js文件是否引入成功-->
	<script type="text/javascript"
		src="/wk1un2_electricity_digital/Backstage/layui/layui.js"></script>
	<script>
	layui.use([ 'form','layer','jquery','table'], function() {
		var layer = layui.layer, $ = layui.jquery, form = layui.form,table=layui.table;
							var $ = layui.jquery;
							table
									.render({
										elem : '#test',
										toolbar : '#toolbarDemo',
										url : '/wk1un2_electricity_digital/Backstage/getAllEvaluate',
										where : {
											method : 'getAll',
											e_contents : ''
										},
										method : 'POST',
										cols : [ [ {
											type : "checkbox",
											fixed:'left',
											width : 50
										}, {
											field : 'e_id',
											width : 110,
											title : '评价ID',
											fixed:'left',
											sort : true,
											align : "center"
										}, {
											field : 'u_id',
											width : 150,
											title : '评价用户',
											align : "center",
											templet : '#userTpl'
										},  {
											field : 'p_id',
											width : 260,
											title : '评价商品',
											align : "center",
											templet : '#proTpl'
										},  {
											field : 'e_contents',
											width : 200,
											title : '评价内容',
											align : "center"
										},  {
											field : 'e_replycontents',
											width : 200,
											title : '评价回复内容',
											align : "center"
										},  {
											field : 'e_replytime',
											width : 200,
											title : '评价回复时间',
											align : "center"
										},  {
											field : 'e_state',
											width : 200,
											title : '评价状态（是否回复）',
											 templet: '#switchTpl',
											align : "center"
										},     
										{
											title : '操作',
											width : 150,
											toolbar : '#barDemo',
											fixed:'right',
											align : "center"
										} ] ],
										id : 'testReload',
										page : true

									});
							
							
							form.on('switch(p_stateDemo)', function(data) {
					              var e_state = this.checked ? 0 : 1;
					              var e_id = this.value;
					              $.ajax({
					            	  url :'/wk1un2_electricity_digital/Backstage/updateevaluatestate',
					                type : "get",
					                data : {
					                	e_state : e_state,
					                	e_id : e_id
					                },
					                success : function(d) {
					                  if (d.code == 0) {
					                    layer.msg("操作成功！");
					                  }else if (d.code == 1) {
					                    layer.msg("操作成功！");
					                  }else {
					                    layer.msg("操作失败！", {
					                      icon : 5
					                    });
					                  }
					                }
					              })
					            });
							
							
							
							
							
							//删除
							//监听行工具事件
							table.on('tool(test)', function(obj) {
								if (obj.event === 'del') {
									layer.confirm('真的删除行么', function(index) {//删除弹框
										console.log('执行删除');
										console.log(obj.data);
										var url = '/wk1un2_electricity_digital/Backstage/deleteEvaluate';
										$.post(url, {
											"e_id" : obj.data.e_id,
											method : 'delete'
										}, function(data) {
											console.log(data);
											if (data.count > 0) {
												console.log('删除成功');
												window.location.reload();
											}
										}, "json");
									});
								} else if (obj.event === 'edit') {
									console.log(obj.data);
									layer.open({
										type : 2,
										area : [ '600px', '650px' ],
										content : 'Evaluate_update.jsp',
										title : '编辑',//修改
										success : function(layero, index) {
											var body = layer.getChildFrame('body',index);
											body.contents().find("#e_id").val(obj.data.e_id);
											body.contents().find("#u_id").val(obj.data.u_id);							
											body.contents().find("#p_id").val(obj.data.p_id);										
											body.contents().find("#e_contents").val(obj.data.e_contents);	
											body.contents().find("#e_replycontents").val(obj.data.e_replycontents);	
											body.contents().find("#e_replytime").val(obj.data.e_replytime);	
											body.contents().find("#e_state").val(obj.data.e_state);	
										},
										end : function() {
											window.location.reload();
										}
									});
								}
							});
							$('#search').on('click', function() {
								var e_contents = $("#e_contents").val();
								
								table.reload('testReload', {//testReload,是上面渲染表格的id
									where : {//接口需要的两个请求参数
										'e_contents' : e_contents,
										/* 'as_id' : as_id */
									}
								});
							});
						});
					</script>
					<script type="text/html" id="switchTpl">
							  <input type="checkbox" name="e_state" value="{{d.e_id}}" lay-skin="switch" lay-text="已回复|未回复" lay-filter="p_stateDemo" {{ d.e_state == 0 ? 'checked' : '' }}>
							</script>
</body>


</html>